package com.w3cjava.modules.user.controller;

import com.w3cjava.modules.user.entity.User;
import com.w3cjava.modules.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/getUser")
    public User getUser(){
        return new User("admin", "123456", "aa@126.com","2017-06-07 11:12:23");
    }

    /**
     * 插入数据
     * @return
     */
    @GetMapping("/insert")
    public int insert(){
        User user = new User("admin", "123456", "aa@126.com", "2024-03-04 11:12:23");
        user.setId(1L);
        return userService.insertUser(user);
    }

    /**
     * 更新数据
     * @return
     */
    @GetMapping("/update")
    public String update(){
        User user = new User("admin1", "1231456", "aa1@126.com", "2024-03-04 11:12:23");
        user.setId(1L);
        userService.updateUser(user);
        return "update success";
    }

    /**
     * 删除数据
     * @return
     */
    @GetMapping("/delete")
    public String delete(){
        userService.delete(1L);
        return "delete success";
    }

    /**
     * 查询所有数据
     * @return
     */
    @GetMapping("/findAll")
    public List<User> findAll(){
        return userService.findAll();
    }


}
